local manwang = fk.CreateSkill {

  name = "joy__manwang",

  tags = {  },

}



manwang:addEffect("active", {
  name = "joy__manwang",
  anim_type = "special",
  min_card_num = 1,
  target_num = 0,
  can_use = function(self, player)
    return not player:isNude() and player:usedSkillTimes(manwang.name, Player.HistoryPhase) <= 21
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    room:throwCard(effect.cards, manwang.name, player, player)
    for i = 1, #effect.cards, 1 do
      if i > 4 or player:getMark("@manwang") > (4-i) then return end
      doManwang(player, i)
    end
    if not player:hasSkill("joy__huoshou") then
      room:setPlayerMark(player,"joy__manwang",1)
      room:handleAddLoseSkills(player, "joy__huoshou", nil, true, false)
    end
  end,
})

manwang:addEffect(fk.TurnStart, {
  refresh_events = {fk.TurnStart},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("joy__manwang") > 0 and event == fk.TurnStart
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:handleAddLoseSkills(player, "-joy__huoshou", nil, true, false)
    player.room:setPlayerMark(player, "joy__manwang", 0)
  end,
})

return manwang